﻿using MediatR;
using Ordering.Domain.Aggregate;

namespace Ordering.Application.Commands
{
    public class CreateOrderCommand : IRequest
    {

    }

    public class CreateOrderCommandHandler
        : IRequestHandler<CreateOrderCommand>
    {
        private readonly IOrderStogage _orderStogage;

        public CreateOrderCommandHandler(IOrderStogage orderStogage)
        {
            _orderStogage = orderStogage;
        }

        public async Task Handle(CreateOrderCommand request, CancellationToken cancellationToken)
        {
            var order = new Order(200, "1");
            order.AddOrderItme(new OrderItem(3, 200, "衣服"));
            order.AddOrderItme(new OrderItem(2, 100, "鞋子"));
            _orderStogage.Add(order);
            await _orderStogage.UnitOfWork.SaveEntitiesAsync(cancellationToken);
        }
    }
}
